public class Test33 {
    public static void main(String[] args) {
        Army army =new Army(3);
        try {
            army.AddWeapon(new Tank());
            army.AddWeapon(new Ji40YunShu());
            army.AddWeapon(new Pao30());
        } catch (AddWeaponException e) {
            System.out.println(e.getMessage());
        }
        army.moveAll();
        army.addackALL();

    }
}
//移动接口
interface Moveable{
    void move();
}
//攻击接口
interface Shootable{
    void shoot();
}
//军队类
class Army{
    private Weapon[] weapons;

    public Army(int weapons) {
        this.weapons =new Weapon[weapons];
    }

    public Weapon[] getWeapons() {
        return weapons;
    }
    public void setWeapons(Weapon[] weapons) {
        this.weapons = weapons;
    }
    //传入武器
    public void AddWeapon(Weapon we) throws AddWeaponException {
        for (int i = 0; i < weapons.length; i++) {
            if(weapons[i] == null){
                weapons[i]=we;
                return;
            }
            throw new AddWeaponException("武器已满，无法添加！");
        }
    }
    //方法
    public void moveAll(){
        for (int i = 0; i < weapons.length; i++) {
            if(weapons[i] instanceof Moveable){
                Moveable moveable =(Moveable) weapons[i];
                moveable.move();
            }
        }
    }
    //攻击方法
    public void addackALL(){
        for (int i = 0; i < weapons.length; i++) {
            if(weapons[i] instanceof Shootable){
                Shootable shootables =(Shootable) weapons[i];
                shootables.shoot();
            }
        }

    }
}
//异常类
class AddWeaponException extends Exception{
    public AddWeaponException() {
    }

    public AddWeaponException(String message) {
        super(message);
    }
}
//武器类
class Weapon{

}
//坦克类
class Tank extends Weapon implements Moveable,Shootable{
    @Override
    public void move() {
        System.out.println("坦克正在移动！！！");
    }
    @Override
    public void shoot() {
        System.out.println("坦克攻击！！！");
    }
}
//30炮类
class Pao30 extends Weapon implements Shootable{
    @Override
    public void shoot() {
        System.out.println("30炮攻击！！！");
    }
}
//机-40运输机类
class Ji40YunShu extends Weapon implements Moveable{
    @Override
    public void move() {
        System.out.println("机-40运输机起飞！！！");
    }
}